<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <!-- 1.导入Vue的包 -->
    <script src="./lib/vue-2.4.0.js"></script>
</head>

<body>

    <div id="app">
        <com1 v-bind:parentmsg="msgFormSon" v-on:func="getMsgFormSon"></com1>
    </div>

    <template id="tmpl">
        <div>
            <h1>这是子元素+ {{parentmsg}}</h1>
            <input type="button" value="向父组件传递消息" v-on:click="sendMsg">
        </div>
    </template>


    <script>
        var com1 = {
            template: '#tmpl',
            props: ['parentmsg'],
            data() {
                return {
                    msg: '做一个孝顺的儿子，给爸爸一些钱去挥霍吧'

                }
            },
            methods: {
                sendMsg() {
                    this.$emit('func', this.msg)
                }
            }
        }


        var vm = new Vue({
            el: '#app',
            data: {
                msgFormSon: '这是父组件中的数据，爸爸有100块钱，son 你要不'
            },
            methods: {
                getMsgFormSon(data) {
                    this.msgFormSon = data;
                    console.log(this.msgFormSon);
                }
            },
            components: {
                com1
            }
        });
    </script>
</body>

</html>